import { compile } from "@tailwindcss/node";
import { Scanner } from "@tailwindcss/oxide";
import { readFile } from "node:fs/promises";
import path from "node:path";

// https://github.com/tailwindlabs/tailwindcss/blob/main/packages/%40tailwindcss-cli/src/commands/build/index.ts

const input = path.resolve("./src/App.css");
const inputCss = await readFile(input, "utf8");
const baseDirectory = path.dirname(input);

const compiler = await compile(inputCss, {
  base: baseDirectory,
  polyfills: 0,
  onDependency: () => void 0,
});

const sources = (() => {
  if (compiler.root === "none") return [];
  const root = compiler.root || {
    base: path.resolve("./src"),
    pattern: "**/*",
  };
  return [{ ...root, negated: false }, ...compiler.sources];
})();

const scanner = new Scanner({ sources });
const candidates = scanner.scan();
const outputCss = await compiler.build(candidates);

console.log(outputCss);
